/**
 * 
 */
package truerefactor.codesmell;

import java.util.List;

import truerefactor.graph.ClassNode;
import truerefactor.graph.CodeGraph;
import truerefactor.graph.CodeNode;
import truerefactor.metrics.CBO;
import truerefactor.metrics.CS;
import truerefactor.metrics.DIT;
import truerefactor.metrics.WMC;
import truerefactor.refactor.Refactoring;

/**
 * @author Isaac
 *
 */
public class LargeClass extends CodeSmell {

    /**
     * 
     */
    public LargeClass()
    {
        this.shortName = "LGCL";
        this.name = "Large Class";
        this.description = "";
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.codesmell.CodeSmell#measure(truerefactor.graph.CodeGraph, boolean, java.util.List)
     */
    @Override
    protected double measure(CodeGraph graph, boolean initial, List<List<Refactoring>> sequences)
    {
        double smellFound = 0;
        int numMethods = 0;
        CBO cbo = new CBO();
        CS cs = new CS();
        
        double cboMedian = cbo.measure(graph);
        double csMedian = cs.measure(graph);
        
        List<ClassNode> classes = graph.getClasses();
        
        for (ClassNode cNode : classes) {
            numMethods = cNode.getMethods().size();
            double depth = DIT.measure(cNode);
                        
            if ((CS.measure(cNode) > csMedian) && ((WMC.measure(cNode) / numMethods) > 2)) {
                smellFound++;
            } else if ((CBO.measure(cNode, graph) > cboMedian) && (depth <= 1.0)) {
                smellFound++;
            }
        }
        
        return smellFound;
    }
}
